<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .checked {
            color: red;
            text-decoration: line-through;
        }
    </style>
</head>

<body>
    <input type="text">
    <input type="button" value="添加">
    <ol>
        <li>嘿嘿</li>
        <li>嘿嘿</li>
    </ol>
    <script>
        let ipt = document.querySelector('[type="text"]');
        let btn = document.querySelector('[type="button"]');
        let ol = document.querySelector('ol');
        let lis = ol.children;

        btn.onclick = function () {
            let li = document.createElement('li');
            li.innerText = ipt.value;
            ol.appendChild(li);
            ipt.value = ''; // 清空输入框里的字
            render();
        }

        function render() {
            for (let item of lis) {
                item.onclick = function () {
                    item.classList.toggle('checked');
                }
            }
        }
        render();



    </script>
</body>

</html>